#! user/bin/python
# -*- coding: utf-8 -*-

"""
Created on 2021/8/17 16:37

@File: 简单的客户端_echo-client.py
@Author: LT
@Description: Use of this module
"""
import sys
from socket import *

serverHost = 'localhost'                                # 客户端要连接的服务器域名，本机操作就写localhost等效于127.0.0.1
serverPort = 50007                                      # 客户端要连接的服务器端口号

message = [b'Hello Network World!']                     # 待发送的信息

if len(sys.argv) > 1:
    message = (x.encode() for x in sys.argv[1:])
    # print(f"message is {message}")

sockobj = socket(AF_INET, SOCK_STREAM)
sockobj.connect((serverHost, serverPort))               # 客户端是使用connect方法连接服务器，服务器是用accept方法等待客户端连接

for line in message:
    print(f"now line is {line}")
    sockobj.send(line)
    data = sockobj.recv(1024)
    print("Client received--->", data)

sockobj.close()
